'''
    解析wiznote数据库，sqlite3

'''

import sqlite3
import pandas as pd

db_file = r'C:\Users\10365\Documents\My Knowledge\Data\1036522761@qq.com\index.db'

def read_wiznote_db(db_file):
    with sqlite3.connect(db_file) as conn:

        c = conn.cursor()

        # 转化为pandas dataframe
        df = pd.read_sql_query("SELECT * from WIZ_DOCUMENT ORDER BY DT_CREATED DESC", conn)
        print(df.head())
    return df

if __name__ == '__main__':
    df = read_wiznote_db(db_file)
    df.to_csv('wiznote.csv')
    # 遍历df 获取 DOCUMENT_GUID 和 DOCUMENT_TITLE
    for index, row in df.iterrows():
        print(row['DOCUMENT_GUID'], row['DOCUMENT_TITLE'])
        break
